{extend name="public/base"}

{block name="x-body"}
<style>
    .layui-form .layui-input-inline {
        width: 320px;
    }
</style>
    <div class="x-body">
        <form class="layui-form">
            {if $id}
            <input type="hidden" name="id" value="{$id}">
            {/if}
          <div class="layui-form-item">
              <label for="username" class="layui-form-label">
                  会员昵称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="username" name="username" {if $id}disabled{else /} required="" lay-verify="required"{/if}
                  autocomplete="off" value="{$res.username}" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>将会成为您的登入名之一
              </div>
          </div>
            <div class="layui-form-item">
                <label for="mobile" class="layui-form-label">
                    手机号码
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="mobile" name="mobile" required="" lay-verify="phone"
                    autocomplete="off" value="{$res.mobile}" class="layui-input" onfocus="isNum(this)">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您的登入名之一，并且是更改您密码的途径之一
                </div>
            </div>
            <div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">
                    会员密码
                </label>
                <div class="layui-input-inline">
                    <input type="password" id="L_pass" name="password" placeholder="{$id ? '空则为不修改密码' : ''}" required="" lay-verify="pass"
                           autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>6到16个字符
                </div>
            </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
                  确认密码
              </label>
              <div class="layui-input-inline">
                  <input type="password" id="L_repass" name="repassword" required="" lay-verify="repass"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>
              </div>
          </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>会员等级
                </label>
                <div class="layui-input-inline">
                    <select name="level" lay-filter="controller">
                        {volist name="level" id="v"}
                        <option value="{$v.id}" {eq name='v.id' value='$res.level'}selected{/eq}>{$v.level_name}</option>
                        {/volist}
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>

            <div class="layui-form-item">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="0" title="男" {$res.sex == 0 ? 'checked' : ''}>
                    <input type="radio" name="sex" value="1" title="女" {$res.sex == 1 ? 'checked' : ''}>
                    <input type="radio" name="sex" value="2" title="保密" {$res.sex == 2 ? 'checked' : ''}>
                </div>
            </div>


            </div>

          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" lay-submit="">
                  {$id ? '修改' : '增加'}
              </button>
          </div>
      </form>
    </div>
    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        
          //自定义验证规则
          form.verify({
            nikename: function(value){
              if(value.length < 5){
                return '昵称至少得5个字符啊';
              }
            },
            pass: {if !$id}[/(.+){6,12}$/, '密码必须6到12位']{else}''{/if},
            repass: function(value){
                if($('#L_pass').val()!=$('#L_repass').val()){
                    return '两次密码不一致';
                }
            }
          });
        });

        formData('{:url("users/user_form")}', 'add', function (){
            parent.location.reload();
            // 获得frame索引
            var index = parent.layer.getFrameIndex(window.name);
            //关闭当前frame
            parent.layer.close(index);
        }, false);
    </script>
{/block}